package com.glaive;

import cn.hutool.core.io.FileUtil;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TxtHandleCmd {
    static String filePath = System.getProperty("user.dir") + "\\工业霸主0605.txt";

    public static void main(String[] args) throws Exception {
        readLine();
    }

    public static void readLine2() throws Exception {
        ArrayList<String> readUtf8Lines = FileUtil.readUtf8Lines(filePath, new ArrayList<>());
        for (int i = 0; i < readUtf8Lines.size(); i++) {
            String ss = readUtf8Lines.get(i);
            System.out.println(ss);
        }
    }

    /**
     *
     */
    public static void readLine() throws Exception {
        //正则说明：
        // 1. 三位数加空格开头
        Pattern pattern = Pattern.compile(
                "(\\d\\d\\d )(.*)"
        );

        Files
                .lines(Paths.get(filePath))
                .map(s -> {
                    Matcher m = pattern.matcher(s);
                    if (m.find())
                        return "第" + m.group(1).trim() + "章 " + m.group(2);
                    else
                        return s;
                })
                .forEach(System.out::println);
    }
}